<script setup>

import {Message} from "@arco-design/web-vue";
import {useRouter} from "vue-router";
import {useStore} from "vuex";

const router = useRouter();
const store = useStore();
router.beforeEach(async (to, from, next) => {
  if (to.meta?.login) {
    const loginUser = await store.dispatch("user/getLoginUser");
    if (!loginUser || loginUser.userId === -1) {
      Message.warning("请先登录")
      router.push({
        name: "Login",
        query: { redirectName: to.name }
      })
    } else next();
  } else next();
})
</script>

<template>
  <div id="root">
    <router-view />
  </div>
</template>

<style scoped>

</style>
